#!/usr/bin/perl
#edit_rsync.cgi

require './remotesync-lib.pl';
&ReadParse();
@minute=(0..59,);
@hour=("*",0..23);
@day=("*",1..31);
@month=("*",1..12);
@week=("*",0..6);
@bindwidth=("Unlimit","2MB/s","4MB/s","8MB/s","16MB/s");
&header($text{'mirror_title'}, "" , "index", 0, 1,);
@conf_line=split(/ /, $in{'sharedir'});
$conf_minute=$conf_line[0];
$conf_hour=$conf_line[1];
$conf_day=$conf_line[2];
$conf_month=$conf_line[3];
$conf_week=$conf_line[4];
$conf_ipmod=$conf_line[6];
$conf_path=$conf_line[7];
$conf_opt=$conf_line[8].$conf_line[9];
@ipmod=split(/::/, $conf_ipmod);
$conf_ip=$ipmod[0];
$conf_mod=$ipmod[1];

$bwv="Unlimit";
foreach(@conf_line){
   if($_=~ /wlimit=(\d+)/){
      $bsspeed=$1 / 1024;
      @bwidth=split(/=/, $_);
      $bwv=$bsspeed."MB/s";
      last;   
   }
}

print "<form name='edform' action=modify.cgi methiod=post onsubmit='on_submit_click()'>\n";
print "<table class=mode1 width=80%>\n";
print "<tr><td width=150>$text{'mirror_ip'}</td><td><input type=text name=ip class=disabletext value=\"$conf_ip\" disabled=true></td></tr>\n";
print "<tr><td width=150>$text{'mirror_modname'}</td><td><input type=text name=mod class=disabletext value=\"$conf_mod\" disabled=true></td></tr>\n";
print "<tr><td width=150>$text{'mirror_path'}</td><td><input type=text name=localpath class=disabletext value=\"$conf_path\" disabled=true></td></tr>\n";

if($conf_line[8] =~ /u/){
    print "<tr><td width=150>$text{'mirror_type'}</td><td><input type=checkbox name=optupd value='yes' checked>$text{'mirror_update'}</td></tr>\n";
}else{
    print "<tr><td width=150>$text{'mirror_type'}</td><td><input type=checkbox name=optupd value='no'>$text{'mirror_update'}</td></tr>\n";    

}
if($conf_line[9] =~ /ete/){

    print "<tr><td width=150></td><td><input type=checkbox name=optdel value='yes' checked>$text{'mirror_delete'}</td></tr>\n";
}else{
    print "<tr><td width=150></td><td><input type=checkbox name=optdel value='no'>$text{'mirror_delete'}</td></tr>\n";    

 
}
print "<tr><td width=150>$text{'bindwidth'}</td><td>";
print "<select name=bw>";
my $bwtxt;
foreach(@bindwidth){
    if($_ =~ /Unlimit/){
	$bwtxt = $text{'unlimit'};
    }
    else{
	$bwtxt = $_;
    }
    if($_ =~ /$bwv/){
       print "<option value='$_' selected>$bwtxt</option>\n";
    }else{
       print "<option value='$_'>$bwtxt</option>\n";
    }
}
print "</select></td></tr>\n";


print "<tr><td width=150>$text{'mirror_rule'}</td><td>$text{'mirror_minute'}\n";
print "<select name=minute size=1>\n";
foreach(@minute){
     if($_ == $conf_minute){
         print "<option value='$_' selected>$_</option>\n";
     }else{
         print "<option value='$_'>$_</option>\n";
     }
}
print "</select>";
print "</td></tr>\n";

print "<tr><td width=150></td><td>$text{'mirror_hour'}&nbsp;&nbsp;\n";
print "<select name=hour size=1>\n";
foreach(@hour){
    if($_ eq $conf_hour){
        print "<option value='$_' selected>$_</option>\n";
    }else{
        print "<option value='$_'>$_</option>\n";
    }
}
print "</select>";
print "</td></tr>\n";

print "<tr><td width=150></td><td>$text{'mirror_day'}&nbsp;&nbsp;\n";
print "<select name=day size=1>\n";
foreach(@day){
    if($_ == $conf_day){
        print "<option value='$_' selected>$_</option>\n";
    }else{
        print "<option value='$_'>$_</option>\n";    
    }
}
print "</select>";
print "</td></tr>\n";

print "<tr><td width=150></td><td>$text{'mirror_month'}\n";
print "<select name=month size=1>\n";
foreach(@month){
    if($_ == $conf_month){
        print "<option value='$_' selected>$_</option>\n";
    }else{
        print "<option value='$_'>$_</option>\n";   
    }
}
print "</select>";
print "</td></tr>\n";





print "</table>\n";

print "<table border=0 class=mode1><tr><td>\n";
print "<input type=submit name=modify value=$text{'mirror_change'} class=button1>\n";
print "<input type=submit name=cancle value=$text{'mirror_cancle'} class=button1 onclick='on_cancle_click()'>\n";
print "</td></tr></table>\n";

print "<input type=hidden name=line_before_change value=\"$in{'sharedir'}\">";
print "<input type=hidden name=line_ip value=\"$conf_ip\">";
print "<input type=hidden name=line_mod value=\"$conf_mod\">";
print "<input type=hidden name=line_path value=\"$conf_path\">";
print "<input type=hidden name=modtype value=change>";





print "</form>\n";

print <<EOF;
<script>
function on_submit_click()
{
    if (document.edform.optupd.checked)
    {
        document.edform.optupd.value = "yes";
    }
    else
    {
        document.edform.optupd.value = "no";
    }




   if (document.edform.optdel.checked)
   {
       document.edform.optdel.value = "yes";
   }
   else
   {
       document.edform.optdel.value = "no";
   }
}

function on_cancle_click()
{
    document.edform.action = "cancle.cgi";
    
}
function on_change_click()
{

}
</script>
EOF

&footer("index.cgi", $text{'index'});
#&redirect("index.cgi");
